node.js | 您所在的位置:网站首页 › node链接redis 报错-4078 › node.js |
我有一个奇怪的 redis 行为: const redis = require('redis'); const { REDIS_URL: redisUrl, REDIS_PASSWORD: redisPassword } = process.env; const client = redis.createClient(redisUrl, { no_ready_check: true, auth_pass: redisPassword }); client.on('connect', () => { redisPassword && client.auth(redisPassword); }); client.on('error', err => { global.console.log(err.message) });但我总是收到以下错误: throw er; // Unhandled 'error' event ReplyError: Ready check failed: NOAUTH Authentication required. 为什么未处理?我设置错误处理程序 为什么 Ready 检查失败?我在选项中禁用它 最佳答案 我不确定为什么您的代码会抛出此错误。但我在我的本地机器上尝试了这段代码,它运行良好。 const redis = require('redis'); const redisPassword = "password" ; const client = redis.createClient({ host : '127.0.0.1', no_ready_check: true, auth_pass: redisPassword, }); client.on('connect', () => { global.console.log("connected"); }); client.on('error', err => { global.console.log(err.message) }); client.set("foo", 'bar'); client.get("foo", function (err, reply) { global.console.log(reply.toString()) })然后运行 node client.js 将输出: connected bar NOAUTH Authentication required 是由于redis处理命令时,发现客户端未通过身份验证,因此向其投诉。 我猜可能是你给createClient的redisUrl有问题,调试一下或者换成我代码的方式试试。希望你能修复它。 还有一件事:client.auth(redisPassword) 不是必需的,因为如果您设置 auth_pass 或 password 选项,redis 客户端将在任何命令之前自动向服务器发送 auth 命令。 关于node.js - Node-Redis:就绪检查失败 - 需要 NOAUTH 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45672568/ |
CopyRight 2018-2019 实验室设备网 版权所有 |